import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import scoreatpercentile
import matplotlib.mlab as mlab
import scipy.stats as st
import csv
import random
from datetime import datetime
from time import strftime

'''
revision of test24
to calculate the false nagetive, false positive

'''

def getCurTime():
    """
    get current time
    Return value of the date string format(%Y-%m-%d %H:%M:%S)
    """
    format='%Y-%m-%d %H:%M:%S'
    sdate = None
    cdate = datetime.now()
    try:
        sdate = cdate.strftime(format)
    except:
        raise ValueError
    return sdate

def build_data_list(inputCSV):
    sKey = []
    fn = inputCSV
    ra = csv.DictReader(file(fn), dialect="excel")
    for record in ra:
        #print record[ra.fieldnames[0]], type(record[ra.fieldnames[-1]])
        for item in ra.fieldnames:
            temp = float(record[item])
            sKey.append(temp)
    sKey = np.array(sKey)
    sKey.shape=(-1,len(ra.fieldnames))
    return sKey

#--------------------------------------------------------------------------
#MAIN

if __name__ == "__main__":
    print "begin at " + getCurTime()
    #inputCSV = "C:/Documents and Settings/wang322/My Documents/My Dropbox/STAT515/proj/st_louis_mo_temp_prep.csv"
    inputCSV = "C:/Documents and Settings/wang322/Desktop/1.csv"
    dataMatrix = build_data_list(inputCSV) # [year, temp, prep]
    iLen = dataMatrix.shape
    #print dataMatrix
    id = range(0,100)
    #print id
    for item in dataMatrix:
        id[int(item[0])] = int(item[1])
    print id
    
    print "end at " + getCurTime()
    print "========================================================================"  

           
